﻿using Newtonsoft.Json.Linq;
using TrinityAPI.Base.Tools;

namespace TrinityAPI.Base
{
    public class ThreadSleep : IAction
    {
        public JToken Invoke(JObject dataset, params JToken[] args)
        {
            var threadSleepTimeOut = args.Length > 0 && args[0].Type == JTokenType.Integer ? args[0].Value<int>() : 0;
            if (threadSleepTimeOut <= 0)
            {
                var constant = dataset.GetJsonObject("constant");
                threadSleepTimeOut = constant.GetJsonObjectIntValue("ThreadSleepTimeOut");
            }

            if (threadSleepTimeOut > 0)
                System.Threading.Thread.Sleep(threadSleepTimeOut);

            return true;
        }
    }
}
